package org.linlinjava.litemall.db.dao;

import org.apache.ibatis.annotations.*;
import org.linlinjava.litemall.db.domain.Checkins;

import java.time.LocalDate;

public interface CheckinMapper {


    // 更新用户签到状态
    @Update("UPDATE user SET total_points = total_points + 1, " +
            "last_checkin_date = #{checkinDate}, " +
            "consecutive_days = #{consecutiveDays} " +
            "WHERE id = #{userId}")
    int updateUserCheckinStatus(@Param("userId") Long userId,
                                @Param("checkinDate") LocalDate checkinDate,
                                @Param("consecutiveDays") int consecutiveDays);

    // 插入签到记录
    @Insert("INSERT INTO checkin_record(user_id, checkin_date, points_earned) " +
            "VALUES(#{userId}, #{checkinDate}, #{pointsEarned})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertCheckinRecord(Checkins record);

    // 查询连续签到天数
    @Select("SELECT consecutive_days FROM user WHERE id = #{userId}")
    Integer getConsecutiveDays(Long userId);
}

// 实体类
